<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">用户名</td>
                    <td>
                        <input type="text" v-model="info.userName">
                    </td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="info.userPwd">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-info" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted}from 'vue'
import axios from 'axios'
import {useStore} from '@/stores/user'
import { useRoute,useRouter } from 'vue-router';
import { isTemplateExpression } from 'typescript';
const route = useRoute();
const router = useRouter();
const abc:any = useStore();
let info:any=ref({
    userName:"",
    userPwd:""
})

const login=()=>{
    axios({
        url:"/api/Use/Login",
        method:"post",
        params:info.value
    })
    .then((res)=>{
        console.log(res);
    if(res.data==-2)
    {
        alert("密码错误");
        return;
    }
    if(res.data==-1)
    {
        alert("用户名不存在");
        return;
    }
        alert("登录成功");
        abc.someState = res.data;
        if(abc.someState.Dname=="admin")
    {
        router.push("/GetUse");
        return;
    }
    else
    {
        router.push("/GetType");
        return;
    }

    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>